<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>createRef</title>
  <!-- react核心库 -->
  <script src="../js/react.development.js"></script>
  <!-- react扩展库支持react操作DOM -->
  <script src="../js/react-dom.development.js"></script>
  <!-- 1.ES6转ES5；2.jsx转js -->
  <script src="../js/babel.min.js"></script>
  <!-- prop操作 -->
  <script src="../js/prop-types.js"></script>
</head>

<body>
  <div id="test"></div>
  <script type="text/babel">
    class Demo extends React.Component {
      // React.createRef()调用后可以返回一个容器，该容器可以存储被ref标识的节点
      // 16.3以后支持
      myRef = React.createRef();
      showData = () => {
        alert(this.myRef.current.value)
        console.log(this.myRef.current.value)
      }
      render() {
        return (
          <div>
            <input ref={this.myRef} type="text" placehold='点击按钮提示信息' />
            <button onClick={this.showData}>点我提示</button>
          </div>
        )
      }
    }
    ReactDOM.render(<Demo />, document.getElementById('test'))
  </script>
</body>

</html>